<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>
<script>
	</script>

<style>
.table>th {
	vertical-align: center;
	background-color: grey;
}
</style>
</head>
<body class="no-skin">
	<div class="page-content">
		<div class="page-header">
			<h1></h1>

		</div>
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
					<div class="widget-box widget-color-blue">
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>基本信息
							</h6>
							<div class="widget-toolbar no-border">
								<a href="#" data-action="collapse"> <i
									class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main">
								<form class="form-horizontal" id="queryForm" method="post">
									<input type="text" hidden="hidden" id="id" name="id"
										value="${paramsMap.id}">
									<input type="text" hidden="hidden" id="isappJudge" 
										value="${paramsMap.isapp}">
									<table id="baseinfo"
										class="table table-bordered table-striped table-hover table-condensed table-responsive table">
										<tr>
											<th>产品渠道ID</th>
											<td><input type="text" class="input-sm form-control" id="isCode"
												style="padding-left: 0px" name="code"
												value="${paramsMap.code}"></td>
										</tr>
										<tr>
											<th>产品渠道名</th>
											<td><input type="text" class="input-sm form-control"
												style="padding-left: 0px" name="kindname" id="prdName"
												value="${paramsMap.kindname}"></td>
										</tr>
										<tr>
											<th>备注</th>
											<td><input type="text" class="input-sm form-control"
												style="padding-left: 0px" name="memo" id="memo"
												value="${paramsMap.memo}"></td>
										</tr>
										<tr>
											<th>所属大产品</th>
											<td>
												<select id="parent_prod_id" name="parent_prod_id">
													<option value="">请选择</option>
													<option value="1" <c:if test="${paramsMap.parent_id eq '1'}">selected="selected"</c:if>>菠萝贷<option>
													<option value="2" <c:if test="${paramsMap.parent_id eq '2'}">selected="selected"</c:if>>微信菠萝贷</option>
													<option value="3" <c:if test="${paramsMap.parent_id eq '3'}">selected="selected"</c:if>>香蕉还卡</option>
													<option value="4" <c:if test="${paramsMap.parent_id eq '4'}">selected="selected"</c:if>>速来贷</option>
													<option value="5" <c:if test="${paramsMap.parent_id eq '5'}">selected="selected"</c:if>>公积金</option>
													<option value="6" <c:if test="${paramsMap.parent_id eq '6'}">selected="selected"</c:if>>全能借钱</option>
													<option value="7" <c:if test="${paramsMap.parent_id eq '7'}">selected="selected"</c:if>>银河黑卡</option>
													<option value="8" <c:if test="${paramsMap.parent_id eq '8'}">selected="selected"</c:if>>借条APP</option>
													<option value="9" <c:if test="${paramsMap.parent_id eq '9'}">selected="selected"</c:if>>熊花花</option>
												</select>

											</td>
										</tr>
										<tr>
											<th>原生应用(外部SDK不需要勾选)</th>
											<td>
												<input type="checkbox" name="isapp" id='isappCheckbox' value="1" class="input-sm form-control">
											</td>
										</tr>
									</table>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button id="btn-cancel" class="btn  btn-inverse  no-border"
						onclick="doCancle()" id="delete">
						<i class="ace-icon fa fa-undo bigger-160"></i> 取消
					</button>

					&nbsp; &nbsp; &nbsp;
					<button id="btn-save" name="btn-save"
						class="btn  btn-success  no-border" type="button">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
				</div>
			</div>
		</div>
	</div>
	<%@ include file="/common/common-js.jsp"%>
	<script type="text/javascript">
		//时间控件
		jQuery(function($) {
			$(".date-picker").datetimepicker({autoclose:true}).next().on(ace.click_event, function(){
				$(this).prev().focus();
			});
			
		    $("#_seq_regionid").bind("change", function () { 
				var select_province = $(this).val();
		    	var citys = $("#_seq_cityid");
		    	citys.empty();
		        $.getJSON(ctx + "/life/region/getCityByProvinceid.action", {provinceid : select_province}, function (returnObj) {
		        	citys.append("<option value='-1'>请选择</option>");
		           for (var i=0;i<returnObj.citys.length; i++) {
		        	   	var city = returnObj.citys[i];
		        	   	citys.append("<option value='" + city.id + "'>" + city.name + "</option>");
		    	   }
		        }).error(function(){//失败处理
				    	$(".load_bg").attr("style","display:none");
					$(".load_img").attr("style","display:none");
					alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效
				});
			});
			
		});
		
		jQuery(function($){
			
			if($('#isappJudge').val() == 1){
				$('#isappCheckbox').attr("checked","true"); 
			}
			
			if($('#id').val() != "-1"){
				$('#isCode').attr("readonly","readonly");
			}
			
			$("#btn-save").click(function(){
				var code = $('#isCode').val();
				var prdName = $('#prdName').val();
				var parentProdId = $('#parent_prod_id').val();
				var id = $('#id').val();
		
				if (code == null || code.trim().length <= 0){
					alert("产品渠道ID不能为空");
					return;
				}
				
				if (prdName == null || prdName.trim().length <= 0){
					alert("产品渠道名不能为空");
					return;
				}
				
				if(parentProdId == null || parentProdId.trim().length <= 0){
					alert("请选择所属大产品");
					return;
				}
			
				if(id == "-1"){
					
					var judge = $.ajax({
						type:"POST",
						url:ctx + "/productChannel/isExist.action",
						data:{code:code},
						cache: false,
				        async : false
					}).responseText;
					
					
					if(judge == "true"){
						alert("产品渠道ID已存在");
						return;
					}
				}
				
				
				var data = $('#queryForm').serializeObject();
				
				$.ajax({
					"dataType": 'json',
					"type": "POST",
					"url": ctx + "/productChannel/editInfo.action",
					"data": data,
					"success": function(resp){
						 parent.parent['__extdialog_active'].dialog('close');
					},
					"error": function(XMLHttpRequest, textStatus, errorThrown) {
						$(".load_bg").attr("style","display:none");
						$(".load_img").attr("style","display:none");
						alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效
					},
				});
			});
		});

		function doCancle(){
			 parent.parent['__extdialog_active'].dialog('close');
		}
</script>
</body>
</html>
